<?php
/*
 * Copyright notice
 * 
 * (c) 2009 MH-Dev.de, Martin Hesse <info@mh-dev.de>
 * 
 * This script is part of the MH-Dev.-Board project. The MH-Dev.-Board 
 * is free software; you can redistribute it and/or modify it under the 
 * terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, 
 * or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty 
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU 
 * General Public License along with this program; if not, 
 * see http://www.gnu.org/licenses/.
 */


/**
 * View_Helper GetPostText
 * 
 * @author	Martin Hesse <info@mh-dev.de>
 * @package	MH-Dev.-Board
 */
class MHDEV_View_Helper_GetPostText extends Zend_View_Helper_Abstract
{
	/*
	 * Get the post text from a post
	 * 
	 * @param int $post_uid uid of a post
	 * 
	 * @return string the text
	 */
	public function GetPostText($post_uid, $is_quote = FALSE)
	{
		// helper
		$author		= new MHDEV_View_Helper_GetAuthor();
		$bbcode		= new MHDEV_View_Helper_BBCode();
		
		// db
		$posts 		= new Posts();
		
		// query
		$getPost	= $posts->find($post_uid);
		
		if($getPost->count() > 0)
		{
			$post	= $getPost->toArray();
			
			if($is_quote)
			{
				$smilies	= $post[0]['text'] == 1 ? true : false;
				$content 	= '<div class="post_quote"><p>';
				$content 	.= MHDEV_Sprintf(Zend_Registry::get('lang')->_('post_quote_header'), array('%uid' => $post[0]['uid'], '%user' => htmlentities($author->GetAuthor($post[0]['user_uid']))));
				$content	.= '</p>';
				$content	.= $bbcode->BBCode(htmlentities($post[0]['text'], null, 'utf-8'), $smilies);
				$content	.= '</div>';
				
				return $content;
			}
			else
			{
				return $post[0]['text'];
			}
		}
		else
		{
			return 'Error';
		}
	}
}